package com.dong.com.love.model;

import android.content.Context;

import com.dong.com.love.cach.CachCallBack;
import com.dong.com.love.cach.CachUtils;

/**
 * Created by Dong on 2016/11/2.
 */

public abstract class InitMoudel<T> {

    private Context context;
    private Class<T> classOfT;
    private String name;
    private int time;
    private T t;

    public InitMoudel(Context context, Class<T> classOfT, String name, int time) {
        this.context = context;
        this.classOfT = classOfT;
        this.name = name;
        this.time = time;
    }

    /*
      从缓存中获取
     */
    public <T>T getDataFromCach() {
        T t = (T)CachUtils.getCach(context, classOfT, name, time);
        return  t;
    }

    /*
      从网络中获取
     */
    public abstract void getDataFromNet();

    /*
      开始获取数据
     */
    public void start() {

        t = getDataFromCach();

        if(t==null){
            getDataFromNet();
        }else{
            doResult(t);
        }
    }

    /*
      处理返回结果
     */
    public abstract void doResult(T t);
}
